/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/**
 * request 网络请求工具
 * 更详细的 api 文档: https://github.com/umijs/umi-request
 */

import { getDvaApp, history } from 'umi';
import request from '@base/utils/request';

request.use(async (ctx, next) => {
  await next();
  const { code, data } = ctx.res || {};
  if (code == 1011 || code == 1010) {
    const { dispatch } = getDvaApp()._store;
    dispatch({
      type: 'user/saveCurrentUser',
    });
  } else if (code == 500302) {
    history.push(data);
  }
});

export default request;
